/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package fr.cpe.dp.projet2.main;

import fr.cpe.dp.projet2.controller.Step2MusicController;
import fr.cpe.dp.projet2.factory.GenericFactory;
import fr.cpe.dp.projet2.model.algo.IAlgorithm;
import fr.cpe.dp.projet2.model.music.IMusic;
import fr.cpe.dp.projet2.model.music.MusicType;
import fr.cpe.dp.projet2.model.musicBuilder.IMusicBuilder;
import fr.cpe.dp.projet2.model.musicPlayer.ConsoleMusicPlayer;
import fr.cpe.dp.projet2.model.musicPlayer.IMusicPlayer;
import fr.cpe.dp.projet2.model.musicPlayer.MusicPlayerObservable;
import fr.cpe.dp.projet2.model.shape.IShape;
import fr.cpe.dp.projet2.view.Step2MusicPlayerView;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sound.midi.MidiUnavailableException;

/**
 *
 * @author Benoit
 */
public class Step2App {
        /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Step2MusicPlayerView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    GenericFactory<IMusicBuilder> musicBuilderFactory = new GenericFactory<IMusicBuilder>("fr.cpe.dp.projet2.model.musicBuilder");
                    GenericFactory<IShape> shapeFactory = new GenericFactory<IShape>("fr.cpe.dp.projet2.model.shape");
                    GenericFactory<IAlgorithm> algorithmFactory = new GenericFactory<IAlgorithm>("fr.cpe.dp.projet2.model.algo");
                    GenericFactory<IMusic> musicFactory = new GenericFactory<>("fr.cpe.dp.projet2.model.music");
                    
                    Map<String,IMusicBuilder> mapMusicBuilders = new HashMap<>();
                    mapMusicBuilders.put("Algo aléatoire", musicBuilderFactory.createObject("RandomBuilder"));
                    mapMusicBuilders.put("Algo d'une gamme", musicBuilderFactory.createObject("RangeBuilder"));
                    
                    Map<String,MusicType> mapMusicTypes = new HashMap<>();
                    mapMusicTypes.put("Un fichier midi", MusicType.FILE_TYPE);
                    mapMusicTypes.put("Générer une musique", MusicType.GENERATED);
                    
                    Map<String,IShape> mapShapeOptions = new HashMap<>();
                    mapShapeOptions.put("Formes ovales", shapeFactory.createObject("OvalShape"));
                    mapShapeOptions.put("Formes rectangulaires", shapeFactory.createObject("RectangleShape"));
                    
                    Map<String,IAlgorithm> mapAlgorithmOptions = new HashMap<>();
                    mapAlgorithmOptions.put("Algorithme aléatoire", algorithmFactory.createObject("RandomAlgorithm"));
                    
                    Step2MusicPlayerView step2MusicPlayerView = new Step2MusicPlayerView(
                        mapShapeOptions.keySet().toArray(new String[1]),
                        mapAlgorithmOptions.keySet().toArray(new String[1])
                    );
                    
                    IMusicPlayer musicPlayer = new MusicPlayerObservable(new ConsoleMusicPlayer());
                    
                    Step2MusicController step2MusicController = new Step2MusicController(
                        step2MusicPlayerView,
                        musicFactory,
                        musicPlayer,
                        mapMusicBuilders,
                        mapMusicTypes,
                        mapShapeOptions,
                        mapAlgorithmOptions
                    );
                } catch (MidiUnavailableException | InstantiationException | IllegalAccessException | ClassNotFoundException ex) {
                    Logger.getLogger(Step2App.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }
}
